<template>
	<view>
		<!-- 行情 -->
		<marketList :list="marketList"></marketList>
	</view>
</template>

<script>
	import {
		mapState,
		mapActions
	} from 'vuex';
	import marketList from '@/components/marketList.vue'
	export default {
		components: { 
			marketList,
		},
		data() {
			return {
				marketList:[],
				timer2: [],
			}
		},
		computed: {
			...mapState({
				userinfo: state => state.user.userinfo,
				myconfig: state => state.user.myconfig
			}),
			hasLogin() {
				return this.userinfo.id ? true : false
			},
			i18n() {
				return this.$t('message');
			}, 
		},
		onShow() {
			this.init();
		},
		onHide() {
			this.cleartimer();
			//缓存 
			uni.setStorage({
				key: 'marketList',
				data: this.marketList,
			})
		},
		methods: {
			init() { 
				uni.setNavigationBarTitle({
					title: this.i18n.market.title
				});
				this.marketList = uni.getStorageSync('marketList'); 
				// this.marketList =getApp().globalData.hang
				let tt = setInterval((e) => {
					return Promise.all([this.getcoinlist()])
				}, 3000);
				this.timer2.push(tt) 
				return Promise.all([this.getcoinlist()])
			},
			cleartimer(){
				console.log(this.timer2.length)
				if (this.timer2.length > 0) {
					for (let i = 0; i < this.timer2.length; i++) {
						clearInterval(this.timer2[i])
					}
					this.timer2 = []
				}
			},
			getcoinlist() {
				//行情列表
				this.$http.post('btc.qi').then(res => { 
					this.marketList = res.data;
				})
			},
		}
	}
</script>

<style>

</style>
